#include<bits/stdc++.h>
using namespace std;
int t,n,a[10001];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        if(a[0]==a[1]==a[2]){
            cout<<a[0]*(n-1)<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
